<?php
/**
 * Description of ImageInfo
 *
 * @author Martin Grossmann <snake.aas@gmail.com>
 * @version 1.0
 * @package Images
 * 
 * @property $Width Width of image
 * @property $Height Height of image
 * @property $ImageType Type of image
 * @property $Size Size of image
 * @property-read $MimeType MimeType of image
 * @property-read $Orientation Orientation of image
 */
class ImageInfo {
  
  const IMAGE_PORTRAIT = 1;
  const IMAGE_LANDSCAPE = 2;
  
  private $_width;
  private $_height;
  private $_mimeType;
  private $_imageType;
  private $_orientation;
  private $_size;
  
  public function __construct($width = null, $height = null, $imageType = null, $size = null){
    $this->_width       = $width;
    $this->_height      = $height;
    $this->_imageType   = $imageType;
    $this->_mimeType    = image_type_to_mime_type($imageType);
    $this->_size        = $size;
    $this->_calcOrientation();
  }
  
  public function __get($name) {
    
    switch ($name) {
      
      case 'Width': 
        return $this->_width;        
        break;
      
      case 'Height':
        return $this->_height;
        break;
      
      case 'MimeType':
        return $this->_mimeType;
        break;

      case 'ImageType':
        return $this->_imageType;
        break;

      case 'Size':
        return $this->_size;
        break;

      case 'Orientation':
        return $this->_orientation;
        break;
    }
    
  }
  
  public function __set($name, $value) {
    
    switch ($name) {
      
      case 'Width': 
        $this->_width = $value;        
        $this->_calcOrientation();
        break;
      
      case 'Height':
        $this->_height = $value;
        $this->_calcOrientation();
        break;

      case 'Size':
        $this->_size = $value;
        break; 

      case 'ImageType':
        $this->_imageType = $value;
        $this->_mimeType = image_type_to_mime_type($value);
        break;            
    }
    
  }
  
  private function _calcOrientation() {
    $this->_orientation = ($this->_width > $this->_height) ? self::IMAGE_LANDSCAPE : self::IMAGE_PORTRAIT;
  }
}

?>
